package main

import (
	"fmt"
	"time"
)

func getSumOfDivisible(num int, divider int, resultChan chan int) {
	sum := 0
	for value := 0; value < num; value++ {
		if value%divider == 0 {
			sum += value
		}
	}
	resultChan <- sum
}

func main() {
	Limit := 1000
	resultChan := make(chan int, 3)
	tStart := time.Now()
	go getSumOfDivisible(Limit, 3, resultChan)
	go getSumOfDivisible(Limit, 5, resultChan)
	go getSumOfDivisible(Limit, 15, resultChan)

	sum3, sum5, sum15 := <-resultChan, <-resultChan, <-resultChan

	sum := sum3 + sum5 - sum15
	tEnd := time.Now()

	fmt.Println(sum)
	fmt.Println(tEnd.Sub(tStart))
}
